import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:safetymonitor/app/core/http/http.dart';
import 'package:safetymonitor/app/core/utils/interface.dart';
import 'package:safetymonitor/app/data/entities/application/get_realtime_person_monitoring_entity.dart';
import 'package:safetymonitor/app/data/entities/home/monitor/person_monitoring_page_entity_entity.dart';
import 'package:safetymonitor/router/app_pages.dart';
/// 人员详情页面
class DetailController extends GetxController {
  PersonMonitoringPageEntityEntity pageEntityEntity =Get.arguments as PersonMonitoringPageEntityEntity;

  GetRealtimePersonMonitoringEntity entity =  GetRealtimePersonMonitoringEntity();

  @override
  void onInit() {
    super.onInit();
    getRealtimePersonMonitoring();
  }

  ///获取 人员实时监测（含人员定位信息 经纬度）
  void getRealtimePersonMonitoring() async {
    final res =
        await HttpUtil().generateGetRequest<GetRealtimePersonMonitoringEntity>(
      Interface.getRealtimePersonMonitoring,
      queryParameters: {
        'id': pageEntityEntity.id,
      },
    ).execute();
    res.onSuccess((result) {
      if (result.data != null) {
        entity = result.data!;
      }
    });
    update();
  }
  ///传入数据 显示人员轨迹
  void onClick(GetRealtimePersonMonitoringPersonLocationDataDO personLocationDataDO) {
    Get.toNamed(Routes.dynamicTrajectoryPage, arguments: personLocationDataDO)?.then((_){
      // 设置系统首选的方向为竖屏
      SystemChrome.setPreferredOrientations([
        DeviceOrientation.portraitUp,
        DeviceOrientation.portraitDown,
      ]);
      SystemChrome.setEnabledSystemUIMode(
        SystemUiMode.manual,
        overlays: SystemUiOverlay.values,
      );
    });;
  }
}
